<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理-登陆</title>
    <link rel="stylesheet" href="system/layuiadmin/layui/css/layui.css">
    <link rel="stylesheet" href="res/css/index.css">
    <script type="text/javascript" src="res/js/vue.min.js"></script>
    <script type="text/javascript" src="res/js/axios.min.js"></script>
</head>
<body>
<div id="container">
    <div></div>
    <div id="app" class="admin-login-background">
        <span v-if="message==0" style="color: red;">&emsp;账号或密码错误</span>
        <form class="layui-form" action="system/system.html" method="post" @submit.prevent="fun1">
            <div>
                <i class="layui-icon layui-icon-username admin-icon admin-icon-username"></i>
                <input type="text" name="name" placeholder="请输入用户名"
                       autocomplete="off" @focus="fofun"
                       class="layui-input admin-input admin-input-username" v-model="name">
            </div>
            <div>
                <i class="layui-icon layui-icon-password admin-icon admin-icon-password"></i>
                <input type="password" name="password"
                       placeholder="请输入密码"
                       autocomplete="off" @focus="fofun"
                       class="layui-input admin-input " v-model="password">
            </div>
            <button class="layui-btn admin-button" type="submit" lay-filter="formDemo">登陆</button>
        </form>
    </div>
</div>
</body>
<script type="text/javascript">
    new Vue({
        el: "#app",
        data: {
            message:-1,
            name:"",
            password:""
        },
        methods:{
            fun1:function () {
                _this=this;
                axios.post('admin/login',{
                    "name":_this.name,
                    "password":_this.password
                }).then(function (value) {
                    var i=value.data;
                    if(i==0){
                        _this.message=0;
                        _this.name="";
                        _this.password="";
                    }else {
                        location.href="system/system.html";
                        _this.name="";
                        _this.password="";
                    }
                }).catch(function (reason) {
                    console.log(reason);
                    alert("程序出错");
                })

            },
            fofun:function () {
                this.message=-1;
            }
        }
    });
</script>
</html>